package com.ruoyi.project.jiaqin.newscomment.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.newscomment.domain.NewsComment;
import com.ruoyi.project.jiaqin.newscomment.service.INewsCommentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 新闻评论Controller
 * 
 * @author admin
 * @date 2020-12-15
 */
@Controller
@RequestMapping("/jiaqin/newscomment")
public class NewsCommentController extends BaseController
{
    private String prefix = "jiaqin/newscomment";

    @Autowired
    private INewsCommentService newsCommentService;

    @RequiresPermissions("jiaqin:newscomment:view")
    @GetMapping()
    public String newscomment()
    {
        return prefix + "/newscomment";
    }

    /**
     * 查询新闻评论列表
     */
    @RequiresPermissions("jiaqin:newscomment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewsComment newsComment)
    {
        startPage();
        List<NewsComment> list = newsCommentService.selectNewsCommentList(newsComment);
        return getDataTable(list);
    }

    /**
     * 导出新闻评论列表
     */
    @RequiresPermissions("jiaqin:newscomment:export")
    @Log(title = "新闻评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NewsComment newsComment)
    {
        List<NewsComment> list = newsCommentService.selectNewsCommentList(newsComment);
        ExcelUtil<NewsComment> util = new ExcelUtil<NewsComment>(NewsComment.class);
        return util.exportExcel(list, "newscomment");
    }

    /**
     * 新增新闻评论
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存新闻评论
     */
    @RequiresPermissions("jiaqin:newscomment:add")
    @Log(title = "新闻评论", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NewsComment newsComment)
    {
        return toAjax(newsCommentService.insertNewsComment(newsComment));
    }

    /**
     * 修改新闻评论
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        NewsComment newsComment = newsCommentService.selectNewsCommentById(id);
        mmap.put("newsComment", newsComment);
        return prefix + "/edit";
    }

    /**
     * 修改保存新闻评论
     */
    @RequiresPermissions("jiaqin:newscomment:edit")
    @Log(title = "新闻评论", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewsComment newsComment)
    {
        return toAjax(newsCommentService.updateNewsComment(newsComment));
    }

    /**
     * 删除新闻评论
     */
    @RequiresPermissions("jiaqin:newscomment:remove")
    @Log(title = "新闻评论", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(newsCommentService.deleteNewsCommentByIds(ids));
    }
}
